package cn.gmcx.lazy.izze.service.impl;

import cn.gmcx.lazy.izze.pojo.Praise;
import cn.gmcx.lazy.izze.mapper.PraiseMapper;
import cn.gmcx.lazy.izze.service.IPraiseService;
import cn.gmcx.lazy.izze.utils.Result;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 点赞表，记录谁点赞了哪条视频 服务实现类
 * </p>
 *
 * @author GMCX
 * @since 2024-08-20
 */
@Service
public class PraiseServiceImpl extends ServiceImpl<PraiseMapper, Praise> implements IPraiseService {

    @Autowired
    private PraiseMapper praiseMapper;
    @Override
    public Integer addPraise(Integer userId, Integer videoId) {
        Praise praise = new Praise();
        praise.setVideoId(videoId);
        praise.setUserId(userId);
        return praiseMapper.insert(praise);
    }

    @Override
    public Boolean getIsPraise(Integer userId, Integer videoId) {
        QueryWrapper<Praise> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        queryWrapper.eq("video_id",videoId);
        long count = praiseMapper.selectCount(queryWrapper);
        if (count != 0){
            return true;
        }else{
            return false;
        }
    }

    @Override
    public void upset(Integer videoId, Integer userId) {
        praiseMapper.upset(videoId,userId);
    }


}
